package com.qf.smartplatform.utils;/*
*王浩政 
*whz
2022/9/8
17:41
*小米商城
*/

import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class MyStringUtils {
    public static String salt="wasdjkl12qwerdfyuiolh5764";
    public static String creatRandomString(int length){
        List<String>list = salt.chars().mapToObj(shuzi -> shuzi + "").collect(Collectors.toList());
        //System.out.println(list);
        StringBuffer stringBuffer=new StringBuffer();
        //打乱集合
        Collections.shuffle(list);
        //创建一个随机的对象
        Random random=new Random();
        for (int i = 0; i < length; i++) {
            //随即得到一个数字
            int randomNum=random.nextInt(351245641);
            //从指定的下标获取数据
            stringBuffer.append(list.get(randomNum%list.size()));
            //System.out.println((char)(salt.chars().findAny().getAsInt()));
        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        new MyStringUtils().creatRandomString(10);
    }
}
